package transformations;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.BufferedReader;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class RecuperationICS {
    long currentDate=0;
    public RecuperationICS(String link) {
        try {
            URL url;
            if(link=="")
            url = new URL("http://planning.univ-st-etienne.fr/ade/custom/modules/"
                    + "plannings/anonymous_cal.jsp?resources=3293&projectId=7&cal"
                    + "Type=ical&firstDate=2013-08-19&lastDate=2014-08-18");
            else url=new URL(link);
            HttpURLConnection http=(HttpURLConnection) url.openConnection();
            long d=http.getDate();
            if(d<currentDate)return;
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            FileWriter fw = new FileWriter("ADECal.ics");
            BufferedWriter writer = new BufferedWriter(fw);
            String line;
            while ((line = reader.readLine()) != null) {
                //System.out.println(line);
                writer.write(line);
                writer.newLine();
            }

            reader.close();
            writer.close();
            currentDate=d;
        } catch (MalformedURLException ex) {
            System.out.println("URL malformée");
        } catch (IOException ex) {
            System.out.println("erreur de connexion");
        }
    }

    public static void main(String[] a) {
       //RecuperationICS r = new RecuperationICS("");

    }
}
